package com.sihan.swvp.action.sys;

import java.util.HashMap;
import java.util.Map;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sihan.swvp.action.BaseAction;
import com.sihan.swvp.service.sys.LogService;


@Controller
@RequestMapping("/logAction")
public class LogAction extends BaseAction{
	
	@Autowired
	LogService logService;
	
	@ResponseBody
	@RequestMapping(value="/getSystemLog")
	public Object getSystemLog(@Param("title")String title,@Param("mark")String mark,
			@Param("startTime")String startTime,@Param("endTime")String endTime,@Param("content")String content,
			@Param("page")Integer page,@Param("limit")Integer limit){
		try {
			
			Map<String, Object> params=new HashMap<String, Object>();
			params.put("title", title);
			params.put("mark", mark);
			params.put("content", content);
			params.put("startTime", startTime);
			params.put("endTime", endTime);
			logService.addUserLog("查看日志", "日志", getLoginUser().getId(),getLoginUser().getName()+ "查看日志",getRemoteAddr(),1,1);
			return pageData(logService.getSystemLog(page,limit,params));
		} catch (Exception e) {
			return failMsg();
		}
	} 
	
	@ResponseBody
	@RequestMapping(value="/delSystemLog")
	public Object delSystemLog(@Param("ids") int[] ids){
		try {
			logService.delSystemLogs(ids);
		} catch (Exception e) {
			failMsg("服务器异常");
		}
		
		return successMsg();
	} 
	
	
	@ResponseBody
	@RequestMapping(value="/getUserLog")
	public Object getUserLog(@Param("title")String title,@Param("mark")String mark,
			@Param("startTime")String startTime,@Param("endTime")String endTime,@Param("content")String content,
			@Param("page")Integer page,@Param("limit")Integer limit){
		
		Map<String, Object> params=new HashMap<String, Object>();
		params.put("title", title);
		params.put("mark", mark);
		params.put("content", content);
		params.put("startTime", startTime);
		params.put("endTime", endTime);
		logService.addUserLog("查看日志", "日志", getLoginUser().getId(),getLoginUser().getName()+ "查看日志",getRemoteAddr(),1,1);
		return pageData(logService.getUserLog(page, limit, params));
	} 
	
	@ResponseBody
	@RequestMapping(value="/delUserLogs")
	public Object delUserLogs(@Param("ids")int[] ids,String[] para){
		try {
			logService.delUserLogs(ids);
			logService.addUserLog("删除日志", "日志", getLoginUser().getId(),"被删日志标题："+para[1]+",被删日志内容："+para[0] ,getRemoteAddr(),1,0);
		} catch (Exception e) {
			failMsg("服务器异常");
		}
		
		return successMsg();
	} 
	
}
